#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <linux/videodev2.h>
#include <string.h>

int main()
{
	int fd = open("/dev/video3",O_RDWR);
	if(fd < 0){
		perror("打开设备失败");
		return -1;
	}

	struct v4l2_format vfmt;
	vfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	vfmt.fmt.pix.width = 1280;
	vfmt.fmt.pix.height = 720;
	vfmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;

	int ret = ioctl(fd,VIDIOC_S_FMT,&vfmt);
	if(ret < 0){
		perror("设置格式失败\r\n");
	}
	memset(&vfmt,0,sizeof(vfmt));
	vfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	ret = ioctl(fd,VIDIOC_G_FMT,&vfmt);
	if(ret < 0){
		perror("设置格式失败");
	}

	if(vfmt.fmt.pix.width == 1280 && vfmt.fmt.pix.height == 720 && vfmt.fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV){
		printf("设置成功\r\n");
	}
	else{
		printf("设置失败");
	}
	close(fd);
	return 0;
}